package br.unicamp.integralization.request;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.widget.Toast;
import br.unicamp.integralization.AllocationActivity;
import br.unicamp.integralization.R;

public class RequestControllerTask extends RequestTask {

	public static final String URL_GET_DATA = "http://www.students.ic.unicamp.br/~ra104864/mc857/servidorDac/rest/obter_dados.php";

	private Activity mActivity;
	private ProgressDialog pd;

	public RequestControllerTask(Activity mActivity) {
		super();
		this.mActivity = mActivity;
		this.pd = ProgressDialog.show(mActivity, "",
				mActivity.getString(R.string.loading), true);
	}

	@Override
	protected void onPostExecute(RequestDTO result) {
		if (result.getStatus() == RequestStatusEnum.OK.code()) {
			Intent intent = new Intent(mActivity.getApplicationContext(),
					AllocationActivity.class);
			intent.putExtra(AllocationActivity.HISTORY_JSON, result.getMsg());
			pd.dismiss();
			mActivity.startActivity(intent);
		} else {
			pd.dismiss();
			Toast.makeText(
					mActivity,
					"Ocorreu um erro. Verifique sua conexão, o RA digitado, e tente novamente",
					Toast.LENGTH_LONG).show();
		}
	}

}
